'''
Created on Nov 5, 2013

@author: haind
'''
import time
import database
from threading import Thread

import db
import threading
import CONSTANTS
class NotiInapp(Thread):
    '''
    Main worker for "login", "logout", "getnoti", "settoken"
    '''
    def __init__(self):
        threading.Thread.__init__(self)
        self.db_pool = db.NotiInapp()
#         self.mysql = database.cache()._handlemysql.mysql
#         for _ in range(0, CONSTANTS.MAX_MAJOR_WORKERS):
#             Thread(target=self.work).start()
#------------------------------------------------------------------------------ 
    def work(self):
        while True:
            v_task = self.db_pool.get_waiting_task()
            if not v_task:
                time.sleep(0.005)
                continue
            self.db_pool.rt_all(v_task)  

    def run(self):
        for _ in range(0, CONSTANTS.MAX_MAJOR_WORKERS):
            Thread(target=self.work).start()
#         self.work()